π Learning Objectives
π We are learning to consolidate our understanding of Python
β Outcomes
- We will consolidate our understanding of inputs, outputs and variables
- We will consolidate our understanding of Selection IF and ELIF
- We will consolidate our understanding of While loops and For Loops
- We will consolidate our understanding of Lists (1D and 2D)
π Activity 1 β Inputs, Outputs and Variables
π Activity 1.1 - Assign an input to a variable and output it
Your task:
- Create a variable called sport
- Use
input()to ask the user for their favourite sport - Store the userβs answer in the variable
- Use
print()to output a sentence saying that you also like that sport - Make sure the sport name appears in the output
Click to see how this should look
sport = input("Input your favourite sport: ")
print(f"Wow, I really like {sport} as well!")
π Activity 1.2 Casting an input to an integer and multiplying it
Your task:
- Create a variable called num
- Use
input()to ask the user for a number - Convert the input into an integer using
int() - Multiply the number by 2
- Output the result using
print()
Click to see how this should look
num = int(input("Enter a number you wish to multiply by 2: "))
print(num * 2)
π Activity 2 β Selection and Branching Selection
π Activity 2.1 - Working with selection (IF / ELSE)
Your task:
- Create a variable called capital
- Ask the user to enter the capital city of Poland
- Use an
if / elsestatement to check the answer - Compare the answer to
"warsaw"using.lower() - Output Correct! if the answer is right
- Output Incorrect if the answer is wrong
Click to see how this should look
capital = input("Name the capital of Poland: ")
if capital.lower() == "warsaw":
print("Correct!")
else:
print("Incorrect")
π Activity 2.2 - Working with selection (IF / ELIF / ELSE)
Your task:
- Create a variable called colour
- Ask the user to enter a primary colour
- Use an
if / elif / elsestatement - Check for red, blue, or yellow
- Use
.lower()when comparing values - Output Correct! for a primary colour
- Output Incorrect for any other answer
Click to see how this should look
colour = input("Name a primary colour: ")
if colour.lower() == "red":
print("Correct!")
elif colour.lower() == "blue":
print("Correct!")
elif colour.lower() == "yellow":
print("Correct!")
else:
print("Incorrect")
π Activity 3 β While loops
π Activity 3.1 - Working with a conditional while loop
Your task:
- Create a variable called password
- Ask the user to enter the password
- Use a
whileloop that runs while the password is not Secret123 - Inside the loop:
- Tell the user the password is incorrect
- Ask them to enter the password again
- After the loop ends, output Password accepted
Click to see how this should look
password = input("Enter the password: ")
while password != "Secret123":
print("Password is incorrect, please try again: ")
password = input("Enter the password: ")
print("Password accepted")
π Activity 3.2 - Working with a while True loop
Your task:
- Start a
while Trueloop - Ask the user to enter a primary colour
- Store the answer in a variable called guess
- Use
if / elif / elseto check for:- red
- yellow
- blue
- If the answer is correct:
- Output Correct
- Use
breakto stop the loop
- If the answer is incorrect:
- Output Incorrect
- Allow the loop to continue
Click to see how this should look
while True:
guess = input("Input a primary colour: ")
if guess.lower() == "red":
print("Correct")
break
elif guess.lower() == "yellow":
print("Correct")
break
elif guess.lower() == "blue":
print("Correct")
break
else:
print("Incorrect")
π Activity 4 β For Loops and Lists
π Activity 4.1 - For loop to output the 8 times table
Your task:
- Create a
forloop that runs from 1 to 12 - In each loop:
- Multiply the loop variable by 8
- Output the calculation in a clear sentence
- Use an f-string to format the output
Example output:
1 X 8 = 8 2 X 8 = 16 3 X 8 = 24
Click to see how this should look
for i in range(1, 13):
print(f"{i} X 8 = {i * 8}")
π Activity 4.2 - For loop through a 1 dimensional list
Your task:
- Use the list of Olympic sports provided
- Create a
forloop that runs through every item in the list - Use the loop counter to access each sport
- Output a sentence stating that each sport will feature in the 2028 Olympics
- Use an f-string to format the output
Given list:
sports = ["Shotput", "Javelin", "Triple Jump", "High Jump", "Discus", "Diving"]
Click to see how this should look
#index 0 1 2 3 4 5
sports = ["Shotput", "Javelin", "Triple Jump", "High Jump", "Discus", "Diving"]
for i in range(0, 6):
print(f"{sports[i]} will feature in the 2028 Olympics")
π Activity 5 β Outputting data from 2 Dimensional Lists
π Activity 5.1 - Output both items in each record
- You have been given a 2 dimensional list comprised of the following records
landmarks = [
["Eiffel Tower", "Paris"],
["Taj Mahal", "Agra"],
["Forbidden Palace", "Beijing"],
["Golden Gate Bridge", "San Francisco"],
["Royal Mile", "Edinburgh"],
["Burj Khalifa", "Dubai"],
["Hagia Sophia", "Istanbul"],
["Sagrada Familia", "Barcelona"]
]
The Eiffel Tower is in Paris The Taj Mahal is in Agra The Forbidden Palace is in Beijing etc....
Click to see how this should look
landmarks = [
["Eiffel Tower", "Paris"],
["Taj Mahal", "Agra"],
["Forbidden Palace", "Beijing"],
["Golden Gate Bridge", "San Francisco"],
["Royal Mile", "Edinburgh"],
["Burj Khalifa", "Dubai"],
["Hagia Sophia", "Istanbul"],
["Sagrada Familia", "Barcelona"]
]
for i in range(0, 8):
print(f"The {landmarks[i][0]} is in {landmarks[i][1]}")
π Activity 5.2 - Searching a 2 Dimensional List
Your task:
- Use the list of athletes and medals provided
- Create a variable called search
- Ask the user to enter a medal type:
- bronze
- silver
- gold
- Create a
forloop that runs through every record - In each loop:
- Check if the medal matches the userβs search
- If it matches, output the athleteβs name and medal
Given list:
medals = [
["Keely Hodgkinson", "gold"],
["Adam Peaty", "gold"],
["Duncan Scott", "silver"],
["Ben Proud", "silver"],
["Tom Daley", "bronze"],
["Bradley Wiggins", "bronze"],
["Jessica Ennis-Hill", "gold"],
["Christine Ohuruogu", "bronze"]
]
Click to see how this should look
search = input("Input a type of medal (bronze, silver or gold): ")
for i in range(0, 8):
if medals[i][1] == search.lower():
print(f"{medals[i][0]} won {medals[i][1]}")